import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import {JVxeTypes,JVxeColumn} from '/@/components/jeecg/JVxeTable/types'
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '楼栋',
    align:"center",
    dataIndex: 'buildName'
   },
   {
    title: '楼层',
    align:"center",
    dataIndex: 'storeyId_dictText'
   },
   {
    title: '房间号',
    align:"center",
    dataIndex: 'roomCode'
   },
   {
    title: '房间类型',
    align:"center",
    dataIndex: 'roomSex_dictText'
   },
   {
    title: '房间描述',
    align:"center",
    dataIndex: 'roomDesc'
   },
   {
    title: '宿舍员',
    align:"center",
    dataIndex: 'managerName'
   },
   {
    title: '舍长',
    align:"center",
    dataIndex: 'headerName'
   },
   {
    title: '状态',
    align:"center",
    dataIndex: 'status',
    customRender:({text}) =>{
      return !text?"":(text=='0'?'停用':'启用')
    },
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
	{
      label: "楼栋",
      field: "buildId",
      component: 'JDictSelectTag',
      componentProps:{
          dictCode:"dorm_build where del_flag='0' and status='1',build_name,id"
      },
      colProps: {span: 4},
 	},
	{
      label: "房间号",
      field: "roomCode",
      component: 'Input',
      colProps: {span: 4},
 	},
   {
    label: "是否空房间",
    field: "isExistsFreeBed",
    component: 'Jcheckbox',
    componentProps: {
        options: [
          { label: '是', value: '1' },
          // { label: '否', value: '' },
        ],
    },
    colProps: {span: 4},
 },
	{
      label: "房间类型",
      field: "roomSex",
      component: 'JDictSelectTag',
      componentProps:{
          dictCode:"roomType"
      },
      colProps: {span: 4},
 	},
 
   {
    label: "状态",
    field: 'status',
    component: 'JDictSelectTag',
    componentProps:{
      options: [
        { label: '启用', value: '1' },
        { label: '停用', value: '0' },
       ],
    },
    //colProps: {span: 6},
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '楼栋',
    field: 'buildId',
    component: 'JDictSelectTag',
    slot: 'buildSlot'
  },
  {
    label: '楼层',
    field: 'storeyId',
    component: 'JDictSelectTag',
    slot: 'storeySlot'
    // componentProps:{
    //     dictCode:"dorm_storey,storey_name,id"
    //  },
  },
  {
    label: '房间号',
    field: 'roomCode',
    component: 'Input',
    // component: 'JDictSelectTag',
    // slot: 'roomSlot'
  },
  {
    label: '房间类型',
    field: 'roomSex',
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"roomType"
     },
  },
  {
    label: '房间描述',
    field: 'roomDesc',
    component: 'Input',
  },
  {
    label: '宿管员',
    field: 'managerId',
    required: true,
    // component: 'JSelectPerson',
    component: 'JSelectDormManPerson',
    slot: 'managerIdSlot',
    componentProps: {
      // labelKey: 'managerName'
      labelKey: 'name',
      // buildId:'111'
     
      // buildId: ({ values }) => {
      //   return values.buildId;
      // }
      //isRadioSelection: true
    },
    // dynamicDisabled: ({ values }) => {
    //   return !!values.id;
    // },
    // component: 'JPopup',
    // componentProps: ({ formActionType }) => {
    //     const {setFieldsValue} = formActionType;
    //     return{
    //         setFieldsValue:setFieldsValue,
    //         code:"select_person",
    //         fieldConfig: [
    //             { source: 'id', target: 'managerId' },
    //         ],
    //         multi:false
    //     }
    // },

  },
  {
    label: '舍长',
    field: 'headerId',
    required: true,
    component: 'JSelectPerson',
    componentProps: {
      labelKey: 'name',
      isRadioSelection: true
    },
    // component: 'JPopup',
    // componentProps: ({ formActionType }) => {
    //     const {setFieldsValue} = formActionType;
    //     return{
    //         setFieldsValue:setFieldsValue,
    //         code:"select_person",
    //         fieldConfig: [
    //             { source: 'id', target: 'headerId' },
    //         ],
    //         multi:false
    //     }
    // },

  },
  {
    label: '状态',
    field:"status",
    component: 'JDictSelectTag',
    defaultValue:'1',
    componentProps:{
       options: [
        { label: '启用', value: '1' },
        { label: '停用', value: '0' },
       ],
     },
	  show: false,
     dynamicRules: ({model,schema}) => {
           return [
                  { required: true, message: '状态不能为空!'},
           ];
      },
   },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];
//子表单数据
//子表表格配置
export const dormBedColumns: JVxeColumn[] = [
    {
      title: '床铺号',
      key: 'bedCode',
      type: JVxeTypes.input,
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
        validateRules: [
          { required: true, message: '${title}不能为空' },
        ],
    },
    {
      title: '床铺描述',
      key: 'bedDesc',
      type: JVxeTypes.input,
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
    },
    {
      title: '状态',
      key: 'status',
      type: JVxeTypes.select,
      width:"100px",
      placeholder: '请选择${title}',
      defaultValue:'1',
	  disabled:true,
      options:[{
        label:'启用',
        value:'1',
      },
      {
        label:'停用',
        value:'0',
      }]
    },
    {
      title: '操作',
      key: 'action',
      type: JVxeTypes.slot,
      fixed: 'right',
      width:"240px",
      align: 'center',
      slotName: 'myAction',
    },
  ]


// 高级查询数据
export const superQuerySchema = {
  roomCode: {title: '房间号',order: 0,view: 'text', type: 'string'},
  roomSex: {title: '房间类型',order: 1,view: 'radio', type: 'string'},
  roomDesc: {title: '房间描述',order: 2,view: 'text', type: 'string'},
  storeyId: {title: '楼层',order: 3,view: 'number', type: 'number',dictTable: 'dorm_storey', dictCode: 'id', dictText: 'storey_name'},
  //子表高级查询
  dormBed: {
    title: '宿舍床铺信息',
    view: 'table',
    fields: {
        bedCode: {title: '床铺号',order: 0,view: 'text', type: 'string'},
        roomId: {title: '房间',order: 1,view: 'number', type: 'number'},
        bedDesc: {title: '床铺描述',order: 2,view: 'text', type: 'string'}
    }
  },
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
// 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}